﻿function MindMapNode() {
    this.Id = null;
    this.Text = null;
    this.Position = null;

    this.GraphicsElement = null;

    this.Parent = null;
    this.MindMap = null;

    var current = this;

    this.Show = function () {
        this.GraphicsElement = raphael.rect(this.Position.x, this.Position.y, this.Position.width, this.Position.height);

        var text = raphael.text(this.Position.x + 30, this.Position.y + 30, this.Text);
        text.attr({ fill: "FFF", font: '20px "Arial"' });

        var color = Raphael.getColor();
        this.GraphicsElement.attr({ fill: color, stroke: color, "fill-opacity": 0, "stroke-width": 2, cursor: "move" });


        this.GraphicsElement.drag(this.onmove, this.onstart, this.onend);


        Drawer.RegisterBlockContextMenu(this.GraphicsElement.node, this);
    };



    this.onstart = function () {
        //this.ox = this.type == "rect" ? this.attr("x") : this.attr("cx");
        //this.oy = this.type == "rect" ? this.attr("y") : this.attr("cy");
        this.ox = this.attr("x");
        this.oy = this.attr("y");

        this.animate({ "fill-opacity": .2 }, 500);
    };
    this.onmove = function (dx, dy) {
        //var att = this.type == "rect" ? { x: this.ox + dx, y: this.oy + dy} : { cx: this.ox + dx, cy: this.oy + dy };
        var att = { x: this.ox + dx, y: this.oy + dy };
        this.attr(att);

        for (var i = current.MindMap.Connections.length; i--; ) {
            raphael.connection(current.MindMap.Connections[i]);
        }
        raphael.safari();
    };
    this.onend = function () {
        this.animate({ "fill-opacity": 0 }, 500);
        current.Position.x = this.attr("x");
        current.Position.y = this.attr("y");
    };

    this.Dispose = function () {
        this.GraphicsElement.remove();
    }
}